package com.ymttest.database.sqlwapper.sqrefund;

import java.util.List;

import com.ymt.database.SqlManager;
import com.ymttest.database.model.sqrefund.MchRefundConfig;
import com.ymttest.utils.YMTDateUtil;

public class MchRefundConfigWrapper {
	
	SqlManager manager;

	public MchRefundConfigWrapper() {
		manager = new SqlManager("sqrefund");
	}

	@SuppressWarnings("unchecked")
	public MchRefundConfig selectByPrimaryKey(Long id) {

		MchRefundConfig mchRefundConfig = null;
		List<MchRefundConfig> result = manager
				.getSelectResults(
						"com.ymttest.database.mapping.sqrefund.MchRefundConfigMapper.selectByPrimaryKey",
						id);
		manager.commit();

		if (result.size() > 0) {
			mchRefundConfig = result.get(0);
		}

		return mchRefundConfig;
	}
	
	@SuppressWarnings("unchecked")
	public MchRefundConfig selectByMerchantId(Long merchantId) {

		MchRefundConfig mchRefundConfig = null;
		List<MchRefundConfig> result = manager
				.getSelectResults(
						"com.ymttest.database.mapping.sqrefund.MchRefundConfigMapper.selectByMerchantId",
						merchantId);
		manager.commit();

		if (result.size() > 0) {
			mchRefundConfig = result.get(0);
		}

		return mchRefundConfig;
	}
	
	public int deleteByMerchantId(Long merchantId) {

		int result = manager
				.delete(
						"com.ymttest.database.mapping.sqrefund.MchRefundConfigMapper.deleteByMerchantId",
						merchantId);
		manager.commit();
		
		return result;
	}
	
	public int insert(long mchId) {
		
		MchRefundConfig mchRefundConfig = new MchRefundConfig();
		
		mchRefundConfig.setMch_id(mchId);
		mchRefundConfig.setUser_can_refund(true);
		mchRefundConfig.setNeed_secondary_review(false);
		
		mchRefundConfig.setAdd_time(YMTDateUtil.getDate());
		mchRefundConfig.setUpdate_time(YMTDateUtil.getDate());
		
		int result = manager
				.delete(
						"com.ymttest.database.mapping.sqrefund.MchRefundConfigMapper.insert",
						mchRefundConfig);
		manager.commit();
		
		return result;
	}
	
	public static void main(String[] args) {
		
		MchRefundConfigWrapper test = new MchRefundConfigWrapper();
		
//		SellerLevelHistory sellerLevelHistory = new SellerLevelHistory();
//		
//		sellerLevelHistory.setDDate(YMTDateUtil.getDate());
//		sellerLevelHistory.setSellerID(24635724);
//		sellerLevelHistory.setUpdateTime(YMTDateUtil.getDate());
//		sellerLevelHistory.setUnconfirm_amount(BigDecimal.TEN);
//		
		System.out.println(test.insert(500002491L));
	}
}
